package com.zhangxi;

import com.zhangxi.javabean.Customer;
import com.zhangxi.service.CustomerService;

import java.util.Scanner;

/**
 * ClassName: JDBCMain
 * Package: com.zhangxi
 */
public class JDBCMain {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        CustomerService customerService = new CustomerService();

        int num = 0;
        do {
            System.out.println("------------------客户信息管理------------------");
            System.out.println("--------------------客户列表--------------------");
            System.out.println("ID\t\t姓名\t\t性别\t\t年龄\t\t工资\t\t电话");
            for (Customer customer : customerService.getList()) {
                System.out.println(customer.getId() + "\t\t" + customer.getName() + "\t\t" + customer.getGender()
                        + "\t\t" + customer.getAge() + "\t\t" + customer.getSalary() + "\t\t" + customer.getPhone());
            }
            System.out.println("----------------------------------------------");

            System.out.print("1、添加客户 2、修改客户 3、删除客户 4、退出  请输入（1-4）");
            num = sc.nextInt();
            switch (num) {
                case 1:
                    Customer customer = new Customer();
                    System.out.print("姓名:");
                    customer.setName(sc.next());
                    System.out.print("性别:");
                    customer.setGender(sc.next());
                    System.out.print("年龄:");
                    customer.setAge(sc.nextInt());
                    System.out.print("工资:");
                    customer.setSalary(sc.nextDouble());
                    System.out.print("电话:");
                    customer.setPhone(sc.next());
                    customerService.addCustomer(customer);
                    break;
                case 2:
                    Customer customerUpdate = new Customer();
                    System.out.print("要修改的ID:");
                    customerUpdate.setId(sc.nextInt());
                    System.out.print("姓名:");
                    customerUpdate.setName(sc.next());
                    System.out.print("性别:");
                    customerUpdate.setGender(sc.next());
                    System.out.print("年龄:");
                    customerUpdate.setAge(sc.nextInt());
                    System.out.print("工资:");
                    customerUpdate.setSalary(sc.nextDouble());
                    System.out.print("电话:");
                    customerUpdate.setPhone(sc.next());
                    if (customerService.updateCustomer(customerUpdate)){
                        System.out.println("修改成功");
                    }else {
                        System.out.println("修改失败");
                    }
                    break;
                case 3:
                    System.out.print("要删除的ID:");
                    int id = sc.nextInt();
                    if (customerService.deleteCustomer(id)){
                        System.out.println("删除成功");
                    }else {
                        System.out.println("删除失败");
                    }

            }
            if (num > 5 || num <= 0) {
                System.out.println("----------------------------------------------");
                System.out.println("非法输入");
            }
        } while (num != 4);


    }


}
